//
//  LMJAVManger.m
//  EPA
//
//  Created by lanou3g on 16/4/21.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "LMJAVManger.h"

@interface LMJAVManger ()
@property (nonatomic, strong) AVPlayer *player;

@end
@implementation LMJAVManger

//实现单利方法
+(instancetype)sharManger {
    static LMJAVManger *manger = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (manger == nil) {
            manger = [LMJAVManger new];
            manger.player = [[AVPlayer alloc]init];
        }
    });
    return manger;
}
//播放
- (void) play {
    AVPlayerItem *item = self.itemArray[self.currentIndex];
    [self.player replaceCurrentItemWithPlayerItem:item];
    [self.player play];
}
//暂停
- (void) pause {
    [self.player pause];
}
//跳转进度
- (void) seekToTime: (CMTime) time {
    [self.player seekToTime:time];
}
//上一曲
- (void) previous {
    self.currentIndex --;
    if (self.currentIndex < 0) {
        self.currentIndex = self.itemArray.count - 1;
    }
    [self play];
}
//下一曲
-(void) next {
    self.currentIndex ++;
    if (self.currentIndex >= self.itemArray.count) {
        self.currentIndex = 0 ;
    }
    [self play];
}
@end
